package com.fangrui.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

//Created by ✎﹏ℳ๓独赏☆独醉 on 2025/4/28 21:50
@Slf4j
@Component
//@Aspect
public class TimeAspect {
    @Around("com.fangrui.aop.MyAspectDemo01.pc()")//引用已经定义的切入点表达式
//    @Around("execution(* com.fangrui.service.*.*(..))")//统计哪些方法的执行耗时
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
//        1、记录开始时间
        long start = System.currentTimeMillis();
//        2、运行原始方法
        Object res = joinPoint.proceed();
//        3、记录结束时间
        long end = System.currentTimeMillis();
//        4、求花费时间
        log.info("{}Time taken: {} ms", joinPoint.getSignature(), end - start);
        System.out.println(joinPoint.getSignature() + "方法执行耗时：" + (end - start) + "ms");
        return res;
    }
}
